package com.warm.base.jdk.thread.realize;

/**
 * @Date: 2020/4/2 9:43
 * @Author: LChuang
 * @Description:
 */
public class ImplementsRunnable implements Runnable{
    private String name;

    private Integer copyCount;

    private String word;

    public ImplementsRunnable(String name, Integer copyCount, String word){
        this.name = name;
        this.copyCount = copyCount;
        this.word = word;
    }

    public void copy(){
        int count = 0;
        String threadName = Thread.currentThread().getName();

        while (true){
            if(copyCount > 0){
                System.out.println("Thread: " + threadName + ", copy " + word + ", surplus: " + --copyCount);
                count++;
            } else {
                break;
            }
        }
        System.out.println("Thread: " + threadName + " copy " + count);
    }

    @Override
    public void run() {
        copy();
    }
}
